// pages/addressMan/addressMan.js

const { get } = require("../../utils/util");
import api from '../../utils/util';
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    radio: '1',
    address:[]
  },

  edit(e){
   const index = e.currentTarget.dataset['index'];
   wx.navigateTo({
     url: '/pages/editAddress/editAddress?index='+index,
   })
  },
  jumpToAdd(){
    wx.navigateTo({
      url: '/pages/editAddress/editAddress',
    })
  },
  onChange(event) {
    console.log(event.detail);
    this.setData({
      radio: event.detail,
    });
    app.globalData.currentRadio = event.detail;
    wx.navigateBack({
      delta: -1,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: async function () {
    let address = app.globalData.address;
    const userId = app.globalData.userId;
    // if(address.length<=0){
      const result  = await api.get(`/address/getByUserId/${userId}`);
      if(result && result.success){
        address =  result.data;
        app.globalData.address = address;
      }
    // }
    this.setData({
      address:address
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})